import { Body, Controller, Delete, Get, Param, Post, Query, UseInterceptors } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { YixiantongGoodsServicesService } from './yixiantong-goods-services.service';
import { YixiantongGoodsSerivcesOperateDto, YixiantongGoodsSerivcesSearchListDto } from './yixiantong-goods-services.dto';
import { AuthInterceptor } from 'src/base/auth-interceptor';

@ApiTags('一线通 - 【类目关联服务管理】')
@Controller('/api/yixiantong-goods-services')
@UseInterceptors(new AuthInterceptor())
export class YixiantongGoodsServicesController {
  constructor(
    private readonly yixiantongGoodsServicesService: YixiantongGoodsServicesService
  ) {}

  @Get('/list')
  @ApiOperation({ summary: '获取类目服务分页列表' })
  public async getList(@Query() query: YixiantongGoodsSerivcesSearchListDto) {
    return await this.yixiantongGoodsServicesService.getList(query);
  }

  @Get('/:id')
  @ApiOperation({ summary: '获取服务类目详情' })
  public async getListDetail(
    @Param('id') id: string
  ) {
    return await this.yixiantongGoodsServicesService.getListDetail(Number(id));
  }

  @Post('/')
  @ApiOperation({ summary: '添加 / 更新服务类目' })
  public async createOrUpdateListItem(@Body() formData: YixiantongGoodsSerivcesOperateDto) {
    return await this.yixiantongGoodsServicesService.createOrUpdateListItem(formData);
  }

  @Delete('/:id')
  @ApiOperation({ summary: '删除服务类目' })
  public async deleteListItem(@Param('id') id: string) {
    return await this.yixiantongGoodsServicesService.deleteListItem(Number(id));
  }
}
